//
//  HomeLivingList_TableViewCell.m
//  MZSystem
//
//  Created by 智障 on 2018/11/6.
//  Copyright © 2018 zerod. All rights reserved.
//

#import "HomeLivingList_TableViewCell.h"


@interface HomeLivingList_TableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *titleLab;
@property (weak, nonatomic) IBOutlet UILabel *startTime;
@property (weak, nonatomic) IBOutlet UILabel *endTimeL;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (weak, nonatomic) IBOutlet UIButton *auctionButton;
@property (weak, nonatomic) IBOutlet UIButton *modifyButton;
@property (weak, nonatomic) IBOutlet UILabel *tipLabel;
@property (weak, nonatomic) IBOutlet UILabel *downLabel;

@property (weak, nonatomic) IBOutlet UILabel *lineLabel;

@end



@implementation HomeLivingList_TableViewCell

- (void)setModel:(LivingListModel *)model{
    _titleLab.text = model.title;
    
    _startTime.text = [NSString stringWithFormat:@"开始：%@",[self timeWithTimeEscString:model.beginTime]];
    _endTimeL.text = [NSString stringWithFormat:@"结束：%@",[self timeWithTimeEscString:model.endTime]];
    
    _tipLabel.hidden = YES;
    
    [_auctionButton setTitle:@"开始直播" forState:UIControlStateNormal];
    _auctionButton.backgroundColor = RGB(227,11,11);
    switch (model.status) {
        case 0:{
            _statusLabel.text = @"未开始";
            _statusLabel.textColor = RGB(126,126,126);
//            [_auctionButton setTitle:@"未开始" forState:UIControlStateNormal];
//            _auctionButton.backgroundColor = RGB(201,199,199);
        }
            break;
        case 1:{
            _statusLabel.text = @"直播中";
            _statusLabel.textColor = RGB(210,87,50);
            _tipLabel.hidden = NO;
//            [_auctionButton setTitle:@"开始直播" forState:UIControlStateNormal];
//            _auctionButton.backgroundColor = RGB(227,11,11);
        }
            break;
        case 2:{
            _statusLabel.text = @"已结束";
            _statusLabel.textColor = RGB(126,126,126);
//            [_auctionButton setTitle:@"无回放" forState:UIControlStateNormal];
//            _auctionButton.backgroundColor = RGB(201,199,199);
        }
            break;
            
        default:
            break;
    }
}

- (IBAction)modifyButton:(UIButton *)sender {
    if (self.modifyClick) {
        self.modifyClick();
    }
}
- (IBAction)auctionBtnClick:(UIButton *)sender {
    if (self.actionClick) {
        self.actionClick();
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    _tipLabel.clipsToBounds = YES;
    _tipLabel.layer.cornerRadius = _tipLabel.height/2;
    _tipLabel.hidden = YES;
    
    _auctionButton.clipsToBounds = YES;
    _auctionButton.layer.cornerRadius = 5.f;
    _downLabel.backgroundColor = RGB(239, 239, 239);
    
}
- (NSString *)timeWithTimeEscString:(NSString *)timeString
{
    // 格式化时间
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"MM月dd日  HH:mm"];
    
    // 毫秒值转化为秒
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]];
    NSString* dateString = [formatter stringFromDate:date];
    return dateString;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
